package cn.ibizlab.odoo.core.odoo_hr.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Ihr_leave_report;
import cn.ibizlab.odoo.core.odoo_hr.domain.Hr_leave_report;
import cn.ibizlab.odoo.core.odoo_hr.filter.Hr_leave_reportSearchContext;
import cn.ibizlab.odoo.core.odoo_hr.service.IHr_leave_reportService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[请假摘要/报告] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Hr_leave_reportServiceImpl implements IHr_leave_reportService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Ihr_leave_reportClientService hr_leave_reportClientService;

    @Override
    public void updateBatch(List<Hr_leave_report> hr_leave_reports, int batchSize) {

        //hr_leave_reportClientService.updateBatch(hr_leave_reports,batchSize) ;

    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //hr_leave_reportClientService.removeBatch(hr_leave_reports) ;

    }

    @Override
    public Hr_leave_report get(Integer id) {
        Ihr_leave_report clientModel = hr_leave_reportClientService.createModel();
        clientModel.setId(id);
        hr_leave_reportClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Hr_leave_report get(Hr_leave_report hr_leave_report) {
        Hr_leave_report rethr_leave_report = this.get(hr_leave_report.getId()) ;
    	BeanCopier copier=BeanCopier.create(rethr_leave_report.getClass(), hr_leave_report.getClass(), false);
        copier.copy(rethr_leave_report, hr_leave_report, null);
        return hr_leave_report ;
    }

    @Override
    public boolean create(Hr_leave_report hr_leave_report) {
        boolean bOk = false ;
        Ihr_leave_report clientModel = this.convert2Model(hr_leave_report,null);
        hr_leave_reportClientService.create(clientModel) ;
        this.convert2Domain(clientModel,hr_leave_report);
        bOk = true ;

        return bOk ;
    }

    @Override
    public boolean update(Hr_leave_report hr_leave_report) {
        boolean bOk = false ;
        Ihr_leave_report clientModel = this.convert2Model(hr_leave_report,null);
        hr_leave_reportClientService.update(clientModel) ;
        this.convert2Domain(clientModel,hr_leave_report) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public void createBatch(List<Hr_leave_report> hr_leave_reports, int batchSize) {

                        //hr_leave_reportClientService.createBatch(hr_leave_reports,batchSize) ;

    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Ihr_leave_report clientModel = hr_leave_reportClientService.createModel();
        clientModel.setId(id);
        hr_leave_reportClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Hr_leave_report> searchDefault(Hr_leave_reportSearchContext context) {
        List<Hr_leave_report> list = new ArrayList<Hr_leave_report>();
        Page<cn.ibizlab.odoo.core.client.model.Ihr_leave_report> clientModelList = hr_leave_reportClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ihr_leave_report clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Hr_leave_report>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据HR 部门查询
     */
    @Override
    public Page<Hr_leave_report> selectByOdoo_department(Integer id){
        Hr_leave_reportSearchContext context = new Hr_leave_reportSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Hr_leave_report> list = new ArrayList<Hr_leave_report>();
        Page<cn.ibizlab.odoo.core.client.model.Ihr_leave_report> clientModelList = hr_leave_reportClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ihr_leave_report clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Hr_leave_report>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据员工类别查询
     */
    @Override
    public Page<Hr_leave_report> selectByOdoo_category(Integer id){
        Hr_leave_reportSearchContext context = new Hr_leave_reportSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Hr_leave_report> list = new ArrayList<Hr_leave_report>();
        Page<cn.ibizlab.odoo.core.client.model.Ihr_leave_report> clientModelList = hr_leave_reportClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ihr_leave_report clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Hr_leave_report>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据员工查询
     */
    @Override
    public Page<Hr_leave_report> selectByOdoo_employee(Integer id){
        Hr_leave_reportSearchContext context = new Hr_leave_reportSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Hr_leave_report> list = new ArrayList<Hr_leave_report>();
        Page<cn.ibizlab.odoo.core.client.model.Ihr_leave_report> clientModelList = hr_leave_reportClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ihr_leave_report clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Hr_leave_report>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据休假类型查询
     */
    @Override
    public Page<Hr_leave_report> selectByOdoo_holiday_status(Integer id){
        Hr_leave_reportSearchContext context = new Hr_leave_reportSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Hr_leave_report> list = new ArrayList<Hr_leave_report>();
        Page<cn.ibizlab.odoo.core.client.model.Ihr_leave_report> clientModelList = hr_leave_reportClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ihr_leave_report clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Hr_leave_report>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Ihr_leave_report convert2Model(Hr_leave_report domain , Ihr_leave_report model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = hr_leave_reportClientService.createModel() ;
        }

         if(domain.getDate_toDirtyFlag())
            model.setDate_to(domain.getDate_to());
         if(domain.getTypeDirtyFlag())
            model.setType(domain.getType());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getNumber_of_daysDirtyFlag())
            model.setNumber_of_days(domain.getNumber_of_days());
         if(domain.getPayslip_statusDirtyFlag())
            model.setPayslip_status(domain.getPayslip_status());
         if(domain.getNameDirtyFlag())
            model.setName(domain.getName());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getStateDirtyFlag())
            model.setState(domain.getState());
         if(domain.getDate_fromDirtyFlag())
            model.setDate_from(domain.getDate_from());
         if(domain.getHoliday_typeDirtyFlag())
            model.setHoliday_type(domain.getHoliday_type());
         if(domain.getHoliday_status_id_textDirtyFlag())
            model.setHoliday_status_id_text(domain.getHoliday_status_id_text());
         if(domain.getCategory_id_textDirtyFlag())
            model.setCategory_id_text(domain.getCategory_id_text());
         if(domain.getEmployee_id_textDirtyFlag())
            model.setEmployee_id_text(domain.getEmployee_id_text());
         if(domain.getDepartment_id_textDirtyFlag())
            model.setDepartment_id_text(domain.getDepartment_id_text());
         if(domain.getCategory_idDirtyFlag())
            model.setCategory_id(domain.getCategory_id());
         if(domain.getEmployee_idDirtyFlag())
            model.setEmployee_id(domain.getEmployee_id());
         if(domain.getHoliday_status_idDirtyFlag())
            model.setHoliday_status_id(domain.getHoliday_status_id());
         if(domain.getDepartment_idDirtyFlag())
            model.setDepartment_id(domain.getDepartment_id());
        return model ;
    }

    public Hr_leave_report convert2Domain( Ihr_leave_report model ,Hr_leave_report domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Hr_leave_report();
        }

        if(model.getDate_toDirtyFlag())
            domain.setDate_to(model.getDate_to());
        if(model.getTypeDirtyFlag())
            domain.setType(model.getType());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getNumber_of_daysDirtyFlag())
            domain.setNumber_of_days(model.getNumber_of_days());
        if(model.getPayslip_statusDirtyFlag())
            domain.setPayslip_status(model.getPayslip_status());
        if(model.getNameDirtyFlag())
            domain.setName(model.getName());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getStateDirtyFlag())
            domain.setState(model.getState());
        if(model.getDate_fromDirtyFlag())
            domain.setDate_from(model.getDate_from());
        if(model.getHoliday_typeDirtyFlag())
            domain.setHoliday_type(model.getHoliday_type());
        if(model.getHoliday_status_id_textDirtyFlag())
            domain.setHoliday_status_id_text(model.getHoliday_status_id_text());
        if(model.getCategory_id_textDirtyFlag())
            domain.setCategory_id_text(model.getCategory_id_text());
        if(model.getEmployee_id_textDirtyFlag())
            domain.setEmployee_id_text(model.getEmployee_id_text());
        if(model.getDepartment_id_textDirtyFlag())
            domain.setDepartment_id_text(model.getDepartment_id_text());
        if(model.getCategory_idDirtyFlag())
            domain.setCategory_id(model.getCategory_id());
        if(model.getEmployee_idDirtyFlag())
            domain.setEmployee_id(model.getEmployee_id());
        if(model.getHoliday_status_idDirtyFlag())
            domain.setHoliday_status_id(model.getHoliday_status_id());
        if(model.getDepartment_idDirtyFlag())
            domain.setDepartment_id(model.getDepartment_id());
        return domain ;
    }


}
